const express = require("express")
const mysql = require("mysql")
const app = express()
// router
const users = require('./routers/api/users')

app.use("/api/users",users)

const port = process.env.port  || 5000

const connection = mysql.createConnection({
    host : 'localhost',
    port : 3306,
    user : 'root',
    password : '123',
    database : 'nodedb'
   
})
connection.connect()

let sql = 'select * from xiang'
// str 一定是 "" 这样的，否则''会报错
let str = ""

connection.query(sql,(err,result) => {
    if ( err ) {
        console.log("Error msg"+err.message)
    }
    console.log(result)
    str =  JSON.stringify(result)
   // console.log(str)

})

app.get("/",(req,res) => {
    res.send(str)
})

app.listen(port,() => {
    console.log("zhe ta ma shi sha")
})